﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GamePanel : BasePanel
{
	public Grid gird;
	CanvasGroup canvasGroup;
	public bool pause { get; set; }
	private void Awake() {
		canvasGroup = GetComponent<CanvasGroup>();
		uipanelType = UIPanelType.GamePanel;
	}
	private void Start() {
		// CreateGrid(1);
	}

	public override void OnEnter() {
		canvasGroup.blocksRaycasts = true;
		canvasGroup.alpha = 1;
		transform.SetAsLastSibling();
		GetComponent<RectTransform>().localScale = Vector3.one;
		pause = false;
	}
	public override void OnExit() {
		canvasGroup.blocksRaycasts = false;
		canvasGroup.alpha = 0;
		GetComponent<RectTransform>().localScale = Vector3.zero;
		pause = true;
	}

	public override void OnPause() {
		canvasGroup.blocksRaycasts = false;
		pause = true;
	}

	public override void OnResume() {
		canvasGroup.blocksRaycasts = true;
		pause = false;
	}

	public void OpenPanel(string pnl) {
		uiMng.PushStack((UIPanelType)System.Enum.Parse(typeof(UIPanelType), pnl));
	}


	public void CreateGrid(int selected) {
		int row = 0, column = 0, mine = 0, size = 0;
		if (selected == 0) {
			row = 9; column = 9; mine = 10; size = 110;
		} else if (selected == 1) {
			row = 16; column = 16; mine = 40; size = 64;
		} else if (selected == 2) {
			row = 16; column = 30; mine = 99; size = 42;
		}
		StartCoroutine(_CreateGrid(row, column, mine, size));
	}
	IEnumerator _CreateGrid(int row, int column, int mine, int size) {
		yield return new WaitForEndOfFrame();
		gird.GenerateInitGrid(row, column, mine, size);
	}




}
